setwd("C:/Users/86139/Desktop/R作业")
library(DESeq2)
expr <- read.csv("mRNA_exprSet.csv",header=TRUE, row.names=1)
table(substr(colnames(expr),14,15))
Tumor <- grep("01$",colnames(expr))
Normal <- grep('11$',colnames(expr))

Tumor_matrix <- expr[,Tumor]#提取肿瘤样本组矩阵
Normal_matrix <- expr[,Normal]#提取正常样本组矩阵
expr1 <- cbind(Tumor_matrix,Normal_matrix)#合并矩阵
group <- factor(c(rep("Tumor",times=length(Tumor)),rep("Normal",times=length(Normal))))#创建分组（因子变量）
Data <- data.frame(row.names = colnames(expr1), group = group)#创建分组数据框

dds <- DESeqDataSetFromMatrix(countData = expr1,
                              colData = Data,
                              design = ~ group)
dds2 <- DESeq(dds)
res <- results(dds2, contrast=c("group", "Tumor", "Normal"))#后者为对照组
res <- res[order(res$pvalue),]#按P值从小到大排序
summary(res)#检查
